#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/8/2 16:48
# @Author  : Samge


def get_class(class_path):
    """
    根据类路径实例化对象
    :param class_path: 类路径，如：xxx.xxxx.PolicyUpdatePanel
    :return:
    """
    splits = class_path.split('.')
    model_path = '.'.join(splits[1:-1])
    clz_name = splits[-1]
    modules = __import__(model_path)

    path_list = splits[2:]
    if not path_list:
        return getattr(modules, clz_name)()
    for path in path_list:
        if path == clz_name:
            return getattr(modules, path)
        else:
            modules = getattr(modules, path)
